﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class Type : IEquatable<Type>
    {
        public void ImportList(List<Classes.EducationType> typeList)
        {
            var mdb = new MedregDBDataContext();
            var ListType = new List<Type>();
            foreach (var type in typeList)
            {
                Type type1 = new Type() { ID = type.ID, Name = type.Name };
                Type query;

                if (mdb.Type.LongCount() == 0)
                {
                    mdb.Type.InsertOnSubmit(type1);
                }
                else
                {
                    try
                    {
                        query = mdb.Type.Single(l => l.ID == type1.ID);
                        query.Name = type1.Name;

                    }
                    catch (ArgumentNullException e)
                    {
                    }
                    catch (InvalidOperationException e)
                    {

                        if (!ListType.Contains(type1))
                        {
                            mdb.Type.InsertOnSubmit(type1);
                            ListType.Add(type1);
                        }
                    }
                }
            }
            mdb.SubmitChanges();
        }
        public bool Equals(Type other)
        {
            var i = this.ID.Equals(other.ID);
            var j = this.Name.Equals(other.Name);
            if (i & j)
            {
                return true;
            }
            return false;
        }
    }
}
